import { IsNotEmpty, IsString, IsNumber, Min } from "class-validator";
import { BaseEntity } from "src/baseEntity";
import { Dept } from "src/dept/dept.entity";
import { System } from "src/system/system.entity";
import { Column, Entity, JoinTable, ManyToMany, ManyToOne } from "typeorm";


@Entity("purchase")
export class Purchase extends BaseEntity {
    @ManyToOne(() => System)
    system: System

    @ManyToMany(() => Dept)
    @JoinTable()
    depts: Dept[]

    @Column()
    @IsNotEmpty({ message: '采购人不能为空' })
    @IsString({ message: '采购人必须是字符串' })
    purchaser: string;

    @Column({ type: "timestamp", nullable: true })
    @IsNotEmpty({ message: '采购时间不能为空' })
    purchaseDate: Date;

    @Column()
    @IsNotEmpty({ message: '类别不能为空' })
    category: string;

    @Column()
    @IsNotEmpty({ message: '名称不能为空' })
    @IsString({ message: '名称必须是字符串' })
    name: string;

    @Column()
    @IsNotEmpty({ message: '规格不能为空' })
    @IsString({ message: '规格必须是字符串' })
    specification: string;

    @Column()
    @IsNotEmpty({ message: '数量不能为空' })
    quantity: number;

    @Column()
    @IsNotEmpty({ message: '单价不能为空' })
    unitPrice: number;
}